package com.dengqi.mymodule.activity.network.base;

import com.module.retrofit.utils.RxSchedulers;
import com.module.retrofit.exception.ExceptionConvert;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import io.reactivex.Observable;

/**
 * @Author: dengqi
 * @CreateDate: 2020-10-17 09:40
 * @Description:
 */
public class BasePresenter {

    protected RxAppCompatActivity activity;

    public BasePresenter(RxAppCompatActivity activity){
        this.activity = activity;
    }

    public <T> Observable<T> execute(Observable<T> observable){
        return observable
                .onErrorResumeNext(new ExceptionConvert<>())
                .compose(RxSchedulers.applySchedulers())
                .compose(activity.bindUntilEvent(ActivityEvent.STOP));
    }
}
